/*
 * @Date: 2020-08-25 17:13:22
 * @LastEditors: xujianxing
 * @LastEditTime: 2020-08-25 17:26:49
 * @FilePath: \nili\src\common\interceptor\logging.interceptor.ts
 */
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';

export class LoggingInterceptor implements NestInterceptor {
  intercept(
    context: ExecutionContext,
    next: CallHandler<any>,
  ): Observable<any> | Promise<Observable<any>> {
    console.log('before ....');
    const now = Date.now();
    return next
      .handle()
      .pipe(tap(() => console.log(`After... ${Date.now() - now}ms`)));
  }
}
